module.exports = {
  body: (schema) => {
    return async (req, res, next) => {
      console.log(req.body)
      try {
        const data = req.body // 根据传入的参数类型获取对应的数据
        await schema.validateAsync(data, { abortEarly: false })
        next()
      } catch (error) {
        next(error)
      }
    }
  },
  query: (schema) => {
    return async (req, res, next) => {
      try {
        const data = req.query // 根据传入的参数类型获取对应的数据
        await schema.validateAsync(data, { abortEarly: false })
        next()
      } catch (error) {
        next(error)
      }
    }
  },
  params: (schema) => {
    return async (req, res, next) => {
      try {
        const data = req.params // 根据传入的参数类型获取对应的数据
        await schema.validateAsync(data, { abortEarly: false })
        next()
      } catch (error) {
        next(error)
      }
    }
  }
}
